package mrdemo001;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

//LongWritable, Text, Text, IntWritable  依次是k1,v1,k2,v2 的数据类型
public class WordCountMap extends Mapper<LongWritable, Text, Text, IntWritable>{
	
	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context)
			throws IOException, InterruptedException {
//		System.out.println("map方法执行了");
		// 这里的value就是v1
		String line = value.toString();
		//得到这一行的每个单词，形成一个字符串数组
		String[] words = line.split(",");
		for(String word : words) {
			//输出每一行的每一个单词<k2,v2> 就是 <hello,1>
			context.write(new Text(word), new IntWritable(1));
		}
	}
	
}
